import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Android
import androidx.compose.material.icons.filled.Email
import androidx.compose.material.icons.filled.Phone
import androidx.compose.material.icons.filled.Share
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

// 开发者信息数据类（分离数据与UI）
data class DeveloperInfo(
    val name: String = "Jennifer Doe",
    val title: String = "Android Developer Extraordinaire",
    val phone: String = "+11 (123) 444 555 666",
    val socialHandle: String = "@AndroidDev",
    val email: String = "jen.doe@android.com"
)

@Composable
fun DeveloperProfileScreen(
    modifier: Modifier = Modifier,
    developerInfo: DeveloperInfo = DeveloperInfo()
) {
    val gradientColors = listOf(
        Color(0xFF60C6F7), // 蓝
        Color(0xFFA0F0E6), // 青
        Color(0xFFFFEBCD)  // 粉
    )
    Surface(
        modifier = modifier.fillMaxSize(),
        color = MaterialTheme.colorScheme.background
    ) {
        Column(
            modifier = Modifier
                .fillMaxSize()
                .background(
                    brush = Brush.verticalGradient(gradientColors)
                ),
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            // 顶部图标区域
            Box(
                modifier = Modifier
                    .padding(top = 80.dp)
                    .size(160.dp)
                    .background(
                        color = Color.White,
                        shape = CircleShape
                    )
                    .padding(20.dp),
                contentAlignment = Alignment.Center
            ) {
                Icon(
                    imageVector = Icons.Filled.Android,
                    contentDescription = "Android Developer Logo",
                    modifier = Modifier.size(100.dp),
                    tint = Color(0xFF34A853) // 官方Android绿色
                )
            }

            // 个人信息
            Column(
                modifier = Modifier.padding(top = 32.dp),
                horizontalAlignment = Alignment.CenterHorizontally
            ) {
                Text(
                    text = developerInfo.name,
                    style = MaterialTheme.typography.headlineMedium.copy(
                        fontWeight = FontWeight.Bold,
                        color = Color(0xFF1E3A8A)
                    )
                )
                Text(
                    text = developerInfo.title,
                    style = MaterialTheme.typography.titleMedium.copy(
                        color = Color(0xFF008000), // 调整为绿色以匹配示例
                        fontSize = 18.sp
                    ),
                    modifier = Modifier.padding(top = 8.dp)
                )
            }

            // 占位空间，将联系信息推至底部
            Spacer(modifier = Modifier.weight(1f))

            // 联系信息卡片
            ContactInfoCard(
                phone = developerInfo.phone,
                socialHandle = developerInfo.socialHandle,
                email = developerInfo.email,
                modifier = Modifier.padding(horizontal = 24.dp, vertical = 32.dp)
            )
        }
    }
}

@Composable
private fun ContactInfoCard(
    phone: String,
    socialHandle: String,
    email: String,
    modifier: Modifier = Modifier
) {
    Card(
        modifier = modifier.fillMaxWidth(),
        shape = RoundedCornerShape(16.dp),
        elevation = CardDefaults.cardElevation(defaultElevation = 8.dp),
        colors = CardDefaults.cardColors(
            containerColor = Color.White.copy(alpha = 0.8f) // 半透明白色卡片
        )
    ) {
        Column(
            modifier = Modifier.padding(vertical = 16.dp)
        ) {
            ContactRow(
                icon = Icons.Default.Phone,
                text = phone,
                modifier = Modifier.padding(horizontal = 24.dp, vertical = 8.dp)
            )
            ContactRow(
                icon = Icons.Default.Share,
                text = socialHandle,
                modifier = Modifier.padding(horizontal = 24.dp, vertical = 8.dp)
            )
            ContactRow(
                icon = Icons.Default.Email,
                text = email,
                modifier = Modifier.padding(horizontal = 24.dp, vertical = 8.dp)
            )
        }
    }
}

@Composable
private fun ContactRow(
    icon: ImageVector,
    text: String,
    modifier: Modifier = Modifier
) {
    Row(
        modifier = modifier,
        verticalAlignment = Alignment.CenterVertically
    ) {
        Icon(
            imageVector = icon,
            contentDescription = null,
            modifier = Modifier.size(24.dp),
            tint = Color(0xFF008000) // 调整图标颜色为绿色
        )
        Spacer(modifier = Modifier.width(16.dp))
        Text(
            text = text,
            style = MaterialTheme.typography.bodyLarge.copy(
                color = Color(0xFF1E293B)
            )
        )
    }
}

@Preview(showBackground = true, name = "Developer Profile Preview")
@Composable
fun DeveloperProfilePreview() {
    MaterialTheme {
        DeveloperProfileScreen()
    }
}